/**
 * @author fenglei.you
 */
function TiledLayerTest(){}
TiledLayerTest.prototype.go=function(){
	var stage = new Me.Stage(400,300,'test_area');
	stage.init(0,0);
	
	//背景
	var layer = new Me.TiledLayer("../img/tiles.png",21,12);
	layer.setData(
		this.generateBgData()
		/*
		[
		{x:0,y:0,width:21,height:12,imgX:0,imgY:0,imgWidth:21,imgHeight:12},
		{x:21,y:0,width:21,height:12,imgX:0,imgY:0,imgWidth:21,imgHeight:12},		
		{x:-11,y:6,width:21,height:12,imgX:0,imgY:0,imgWidth:21,imgHeight:12},
		{x:220,y:220,width:50,height:50,imgX:84,imgY:0,imgWidth:21,imgHeight:12}
		]
		*/
	);
	layer.render(stage.getContext());
	
	//障碍物
	var hindLayer = new Me.TiledLayer("../img/tiles.png",21,12);
	hindLayer.setData(		
		[
		{x:21,y:0,width:21,height:12,imgX:21,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*3,y:12*2,width:21,height:12,imgX:21*2,imgY:0,imgWidth:21,imgHeight:12},		
		{x:21*5,y:12*4,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*6,y:12*4,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*7,y:12*4,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*8,y:12*4,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*9,y:12*4,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		
		{x:21*9,y:12*4,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*9,y:12*5,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*9,y:12*6,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*9,y:12*7,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*9,y:12*8,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		
		{x:21*10,y:12*8,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*11,y:12*8,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*12,y:12*8,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*13,y:12*8,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		{x:21*14,y:12*8,width:21,height:12,imgX:21*3,imgY:0,imgWidth:21,imgHeight:12},
		
		{x:21*6,y:12*6,width:21,height:12,imgX:21*4,imgY:0,imgWidth:21,imgHeight:12}
		]		
	);
	hindLayer.render(stage.getContext());
			
	stage.appendChild(hindLayer);
}
TiledLayerTest.prototype.generateBgData=function(){
	var data = [];
	var rows = 30,cols=20;
	var uw = 21,uh=12;
	
	//generate background
	for(var r=0;r<rows;r++){
		for(var c=0;c<cols;c++){
			for(var sub=0;sub<2;sub++){
				var tile={};
				if(sub==0){				
					tile.x=c*uw;
					tile.y=(r-1)*uh;							
				}else{
					tile.x=c*uw-uw/2;
					tile.y=r*uh-uh/2;					
				}
				
				tile.width=uw;
				tile.height=uh;
				tile.imgX=0;
				tile.imgY=0;
				tile.imgWidth=uw;
				tile.imgHeight=uh;
				
				data.push(tile);	
			}			
		}
	}
	
	return data;
}
